import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0;i < n; i ++){
            a[i] = scanner.nextInt();
        }
        for (int i = 0; i < n;i ++){
            b[i] = scanner.nextInt();
        }
        int count = 0;
        boolean flag = false;
        while (!isSatisfy(a) && count < 100){
            for (int i = 0;i < n - 1;i ++){
                if (a[i] > a[i + 1] && b[i + 1] <= b[i]){
                    int temp = a[i];
                    a[i] = b[i + 1];
                    b[i + 1] = a[i];
                    temp = a[i + 1];
                    a[i + 1] = b[i];
                    b[i] = temp;
                    count ++;
                    flag = true;
                }
            }
            if (!flag){
                System.out.println(-1);
                break;
            }else {
                flag = false;
            }
        }
        System.out.println(count);
    }

    private static boolean isSatisfy(int[] a) {
        for (int i = 0; i < a.length - 1 ; i++){
            if (a[i] > a[i + 1]){
                return false;
            }
        }
        return true;
    }
}
